﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CarShop.Domain.Entities;

namespace CarShop.Data.EntityFramework.Mappings
{
    internal class UserConfiguration : EntityBaseConfiguration<User, int>
    {
        public UserConfiguration()
        {
            //Properties
            Property(u => u.Login).IsRequired().HasMaxLength(50);
            Property(u => u.Email).IsRequired().HasMaxLength(50);
            Property(u => u.PasswordHash).IsRequired();
            Property(u => u.PasswordSalt).IsRequired();
            Property(u => u.LastActivityDate).IsRequired();
            Property(u => u.IsDisabled).IsRequired();
            Property(u => u.IsActivated).IsRequired();
            Property(u => u.FailedLoginAttempts).IsRequired();

            //Relations
            this.HasMany(u => u.Roles).WithMany(r => r.Users).Map(
                m => m.MapLeftKey("UserId").MapRightKey("RoleId").ToTable("User_Role"));

           // HasOptional(u => u.UserInfo).WithRequired(u => u.User);
            HasOptional(u => u.UserInfo).WithRequired(u => u.User);
        }
    }
}
